require(['../config'], () => {
    require(['header'], () => {
        class Register {
            constructor() {
                this.yzRegister()
                this.register()
            }
            yzRegister() {
                var name = document.querySelector('#name');
                var pwd = document.querySelector('#pwd');
                var btn = document.querySelector('#btn');
                name.onblur = function(str) {
                        var reg = /^[a-z](\w|\-){5,19}$/i
                        var str = name.value;
                        if (reg.test(str)) {} else {
                            alert('您输入的格式有误,请重新输入');
                            name.value = "";
                        }
                    }
                    //判断密码
                pwd.onblur = function() {
                    var str1 = pwd.value;
                    if (str1.length <= 6) {
                        alert('您输入的密码长度不够6位，请重新输入');
                    }
                    var reg1 = /^\d|\s|\w$/;
                    var res1 = reg1.test(str1);
                }
            }

            register() {
                $('#btn-register').on('click', function() {
                    const username = $('#name').val()
                    const password = $('#pwd').val()
                    const userinfo = {
                        username,
                        password
                    }
                    var users = localStorage.getItem('users')
                    if (users) {
                        users = JSON.parse(users)
                        users.push(userinfo)
                        localStorage.setItem('users', JSON.stringify(users))
                            // return users.username === $('#name').val() && users.password === $('#pwd').val()
                    } else {
                        var arr = [userinfo]
                        localStorage.setItem('users', JSON.stringify(arr))
                    }
                    console.log(222)
                    alert('注册成功，即将跳转登录页')
                    window.open('/index.html')
                })
            }
        }
        new Register()
    })
})